package com.mareas.web.jsf.component;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.model.SelectItem;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.mareas.web.model.Cliente;
import com.mareas.web.service.GenericService;

@SuppressWarnings("restriction")
@ManagedBean
@RequestScoped
@Component
public class InplaceSelectClienteBean {

	@Autowired
	private GenericService genericService;

	private List<Cliente> clientes;
	private List<SelectItem> clientesOptions = null;
	private Integer value;

	@PostConstruct
	public void init() {
		clientesOptions = new ArrayList<SelectItem>();

		clientes = genericService.getAll(Cliente.class);
		for (Cliente cliente : clientes) {
			clientesOptions.add(new SelectItem(cliente, cliente
					.getClienteNombre()));
		}
	}

	public List<Cliente> getClientes() {
		return clientes;
	}

	public void setClientes(List<Cliente> clientes) {
		this.clientes = clientes;
	}

	public List<SelectItem> getClientesOptions() {
		return clientesOptions;
	}

	public void setClientesOptions(List<SelectItem> clientesOptions) {
		this.clientesOptions = clientesOptions;
	}

	public GenericService getGenericService() {
		return genericService;
	}

	public void setGenericService(GenericService genericService) {
		this.genericService = genericService;
	}

	public Integer getValue() {
		return value;
	}

	public void setValue(Integer value) {
		this.value = value;
	}

}
